package model;

public class CustomDateTime {
	private int month;
	private int day;
	private int year;
	private int hour; // stores military time
	private int minute;
	private boolean isAM;
	
	public CustomDateTime(String[] input) {
		if (input != null && input.length >= 5)
		{
			month = Integer.parseInt(input[0]);
			day = Integer.parseInt(input[1]);
			year = Integer.parseInt(input[2]);
			hour = Integer.parseInt(input[3]);
			minute = Integer.parseInt(input[4]);
			//["05","03","1993","2","32"]
			//["month", "day", "year", "hour", "minute"]
		}
	}
	
	public CustomDateTime(String in) {
		month = Integer.parseInt(in.substring(0, 2));
		day = Integer.parseInt(in.substring(3, 5));
		year = Integer.parseInt(in.substring(6, 10));
		hour = Integer.parseInt(in.substring(11, 13));
		minute = Integer.parseInt(in.substring(14, 16));
		
		String AMPM = in.substring(16);
		if("AM".equalsIgnoreCase(AMPM)) {
			isAM = true;
		} else {
			isAM = false;
		}
	}
	
	public String toString() {
		return year + "/" + month + "/" + day + " " + hour + ":00:00";
	}
	
	public String AMPM(boolean in) {
		if(in) {
			return "AM";
		}
		else {
			return "PM";
		}
	}
	
	/**
	 * Returns the time difference in minutes between two CustomDateTime's
	 * @param other
	 * @return
	 */
	public int timeBetween(CustomDateTime other) {
		int out = -1;
		if(other != null) {
			int yearDif = Math.abs(other.getYear() - year);
			int monthDif = Math.abs(other.getMonth() - month);
			int dayDif = Math.abs(other.getDay() - day);
			int hourDif = Math.abs(other.getHour() - hour);
			int minuteDif = Math.abs(other.getMinute() - minute);
			
			monthDif += yearDif * 12;
			dayDif += monthDif * 30;
			hourDif += dayDif * 24;
			minuteDif += hourDif * 60;
			out = minuteDif;
		}
		return out;
	}

	/**
	 * @return the month
	 */
	public int getMonth() {
		return month;
	}

	/**
	 * @return the day
	 */
	public int getDay() {
		return day;
	}

	/**
	 * @return the year
	 */
	public int getYear() {
		return year;
	}

	/**
	 * @return the hour
	 */
	public int getHour() {
		return hour;
	}
	

	/**
	 * @return the minute
	 */
	public int getMinute() {
		return minute;
	}

	/**
	 * @return the isAM
	 */
	public boolean isAM() {
		return isAM;
	}

	
	
}
